package controller

import (
	"haiqiu-go-admin/result"
	"haiqiu-go-admin/service"
	"net/http"
)

func (*LoginLogApi) LoginLogHandle(w http.ResponseWriter, r *http.Request) {
	switch r.Method {
	case http.MethodGet:
		LoginLogAPI.loginLogById(w, r)
		break
	case http.MethodPost:
		LoginLogAPI.loginLogAdd(w, r)
		break
	case http.MethodPut:
		LoginLogAPI.loginLogUpdate(w, r)
		break
	case http.MethodDelete:
		LoginLogAPI.loginLogDeleteBatch(w, r)
		break
	default:
		break
	}
}

func (*LoginLogApi) LoginLogPage(w http.ResponseWriter, r *http.Request) {
	page, err := service.LoginLogService{}.LoginLogPage(w, r)
	if err != nil {
		result.Fail(w, r, err)
		return
	}
	result.Ok(w, r, page)
}

// 根据ID查询数据
func (*LoginLogApi) loginLogById(w http.ResponseWriter, r *http.Request) {
	page, err := service.LoginLogService{}.LoginLogById(w, r)
	if err != nil {
		result.Fail(w, r, err)
		return
	}
	result.Ok(w, r, page)
}

// 新增数据
func (*LoginLogApi) loginLogAdd(w http.ResponseWriter, r *http.Request) {
	add, err := service.LoginLogService{}.LoginLogAdd(w, r)
	if err != nil {
		result.Fail(w, r, err)
		return
	}
	result.Ok(w, r, add)
}

// 批量删除数据
func (*LoginLogApi) loginLogDeleteBatch(w http.ResponseWriter, r *http.Request) {
	add, err := service.LoginLogService{}.LoginLogDeleteBatch(w, r)
	if err != nil {
		result.Fail(w, r, err)
		return
	}
	result.Ok(w, r, add)
}

// 根据ID更新数据
func (*LoginLogApi) loginLogUpdate(w http.ResponseWriter, r *http.Request) {
	add, err := service.LoginLogService{}.LoginLogUpdate(w, r)
	if err != nil {
		result.Fail(w, r, err)
		return
	}
	result.Ok(w, r, add)
}

// LoginLogList 查询所有数据
func (*LoginLogApi) LoginLogList(w http.ResponseWriter, r *http.Request) {
	loginLogList, err := service.LoginLogService{}.LoginLogList(w, r)
	if err != nil {
		result.Fail(w, r, err)
		return
	}
	result.Ok(w, r, loginLogList)
}
